<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:insert="~{include :: header('院校列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mt-2 mb-2">
    <div class="card card-primary card-outline card-outline-tabs mb-0">
        <div class="card-body">
            <form id="formId" class="form-inline">
                <input class="form-control mr-1" placeholder="请输入id/手机/名称" type="text" name="searchKey"/>
                <select class="form-control mr-1" name="status">
                    <option value="">状态</option>
                    <option value="1">显示</option>
                    <option value="0">隐藏</option>
                </select>
                <a class="btn btn-primary btn-rounded mr-1" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                <a class="btn btn-warning btn-rounded" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
            </form>
        </div>
    </div>
    <div class="btn-group" id="toolbar" role="group">
        <a class="btn btn-success" id="btn-course-add">
            <i class="fa fa-plus"></i> 添加
        </a>
    </div>
    <div class="select-table table-striped">
        <table id="bootstrap-table" class="table-striped"></table>
    </div>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">

    var prefix = "/colleges";

    $(function() {
        var options = {
            url: prefix + "/list.json",
            removeUrl: prefix + "/remove.json?id={id}",
            modalName: "院校",
            columns: [
                {
                    field: 'id',
                    title: 'id'
                },
                {
                    field: 'name',
                    title: '名称'
                },
                {
                    field: 'cover',
                    title: '封面',
                    formatter: function(value, row, index) {
                        if (value === "" || value == null) {
                            return "<img class='img-circle img-xs' style='height:50px;width:50px' data-target='self' src='/static/logo-big.png'/>"
                        } else {
                            return $.common.sprintf("<img class='img-circle img-xs' height='50' width='50' data-target='self' src='%s'/>",  value);
                        }
                    }
                },
                {
                    field: 'contacts',
                    title: '联系人'
                },
                {
                    field: 'mobile',
                    title: '电话'
                },
                {
                    field: 'levelId',
                    title: '等级',
                    formatter: function(value, row, index) {
                        switch (value) {
                            case 0 :
                                return "普通"
                            case 0 :
                                return "认证"
                            case 0 :
                                return "合作"
                            case 0 :
                                return "战略合作"
                            default:
                                return "无"
                        }
                    }
                },
                {
                    field: 'viewCount',
                    title: '浏览量'
                },
                {
                    field: 'likeCount',
                    title: '点赞量'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return value > 0 ? '<span class="badge badge-primary">显示</span>' : '<span class="badge badge-danger">隐藏</span>';
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                },
                {
                    title: '操作',
                    align: 'left',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="editColleges(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-search"></i>删除</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

        //添加合作院校
        $('#btn-course-add').click(function (){
            var index = layer.open({
                title: '',
                content: prefix + '/edit.html',
                type: 2,
                shade: 0.2,
                maxmin: false,
                shadeClose: true,
                area: ['90%', '95%']
            });
        })
    });

    //编辑院校
    function editColleges(id) {
        var index = layer.open({
            title: '',
            content: prefix + '/edit.html?id='+id,
            type: 2,
            shade: 0.2,
            maxmin: false,
            shadeClose: true,
            area: ['90%', '95%']
        });
    }
</script>
</body>
</html>